package com.xg.controller;

import com.alibaba.excel.EasyExcel;
import com.xg.listener.OneDataListener;
import com.xg.model.entity.OneData;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/import")
public class ImportController {

    @PostMapping("/oneData")
    public String importOneData(@RequestParam("file") MultipartFile file) {
        try {
            // 使用 EasyExcel 进行导入
            EasyExcel.read(file.getInputStream(), OneData.class, new OneDataListener())
                    .sheet()
                    .doRead();

            return "导入成功";
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败：" + e.getMessage();
        }
    }
}
